 //
//  MainVC.m
//  ProjectforHDX
//
//  Created by Jaesun on 16/6/30.
//  Copyright © 2016年 H.DX. All rights reserved.
//

#import "MainVC.h"
#import "OrderModel.h"
#import "MainTableHeaderView.h" // 表头
#import "MainHandleTableCell.h" // 自定义cell

#import "CSNewOrderVC.h"   // 新建订单中心
#import "CSNewOrderLCVC.h"    // 新建订单LC
#import "CSNewOrderServiceVC.h"   // 新建客服
#import "CSNewOrderManageVC.h"
#import "CSNewOrderReplaceVC.h"

#import "MessageVC.h"  // 我的消息

#import "UserCenterVC.h" // 个人中心
 
#import "showDetailsView.h"

#import "THOpenView.h"

#import "MHScanViewController.h"

#import "MainHeader.h"

#import "DeliveryDetailsVC.h"

#import "CSMyOrderConfirmingTVC.h"//订单详情
#import "OrderDetailsVC.h"//订单详情

#import "CMyOrderVC.h"//我的订单

#import "WCheckgoodsVC.h"//物品盘点

#import "StockInquiryVC.h"//库存查询

#import "ShipmentReportVC.h" //已发货报告

#import "CunquHomeVC.h"

#import "BDAlertView.h"



@interface MainVC ()<UITableViewDelegate, UITableViewDataSource> {
 
     BOOL  isMJRefresh;//是否可以刷新
    NSString *strKey;
}

@property (nonatomic, strong) NSMutableArray *tableArray;
@property (nonatomic, strong) UITableView *tableView;
/**
 *  消息点
 */
@property (nonatomic, strong) RZCustomLable *labPoint;
/**
 *  表头视图
 */
@property (nonatomic, strong) MainTableHeaderView *headerView;
@property (nonatomic, strong) NSMutableArray *cabinetlistArr;  // 智能柜列表数组

@end

static NSString *mainTableCell_ID = @"mainHandleTableCell";

@implementation MainVC

- (void)viewDidLoad {
    
    [super viewDidLoad];
    
    self.tableArray=[[NSMutableArray alloc] initWithCapacity:0];
    [self.leftItem setImage:BDFILEIMAGENAEM(@"UserCenter/user") forState:UIControlStateNormal];
     self.rightItem.hidden=NO;
    [self.rightItem setImage:BDFILEIMAGENAEM(@"Home/btn_msgNotice") forState:UIControlStateNormal];
    self.labPoint=[[RZCustomLable alloc] init];
    [self.labPoint setFrame:CGRectMake(self.rightItem.width-15,6, 9, 9)];
    [self.labPoint addRadius:self.labPoint.width/2.f borderwidth:0 bordercolor:nil];
    [self.labPoint setBackgroundColor:[UIColor orangeColor]];
    self.labPoint.layer.borderWidth = 1;
    self.labPoint.layer.borderColor = SYSTEM_COLOR.CGColor;
    [self.rightItem addSubview:self.labPoint];
    self.cabinetlistArr = [NSMutableArray new];
    
    RZCustomImageView *logoView=[[RZCustomImageView alloc] init];
    UIImage *logo=BDFILEIMAGENAEM(@"Home/nav_logo");
    [logoView setFrame:CGRectMake(0, 0, logo.size.width, logo.size.height)];
    logoView.image=logo;
    self.customTitleView=logoView;
    
    [self setupViews];
    if (![Toolobject isAppStoreTestAccount]) {
         [self requestUpdateInfo];
    }
   
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(hahha) name:@"loginStatus" object:nil];
    
    [self createTHeaderView:nil];
}

- (void)viewWillAppear:(BOOL)animated {
    [super viewWillAppear:animated];
    [self.navigationController setNavigationBarHidden:NO animated:animated];
    isMJRefresh = YES;
    [self addHeader];
    
    // 获取智能柜列表
    [self getSmartCabinet];
        [self.navigationController.navigationBar setShadowImage:[[UIImage alloc]init]];
        

    self.navigationController.navigationItem.rightBarButtonItem.enabled =NO;
    [self getMessage];
}

- (void)hahha{
    NSLog(@"登录进来的");
    [self getHomepageDatas];

}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
}

#pragma mark 视图初始化
- (void)setupViews {

    self.view.backgroundColor = [Toolobject getColorByRGB:244 green:248 blue:251 alpha:1];
 
      // tableView
    self.tableView = [[UITableView alloc] initWithFrame:CGRectMake(0, 0, BOUNDSWIDTH,self.view.height - 64) style:(UITableViewStylePlain)];
    self.tableView.backgroundColor = [UtilCheck getRZColor:244 green:248 blue:251 alpha:1];
    self.tableView.showsVerticalScrollIndicator = NO;
    self.tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
    
    self.tableView.delegate = self;
    self.tableView.dataSource = self;
    [self.tableView registerClass:[MainHandleTableCell class] forCellReuseIdentifier:mainTableCell_ID];
    [self.view addSubview:self.tableView];
}

#pragma mark- TableViewDelegate
- (NSInteger) numberOfSectionsInTableView:(UITableView *)tableView {
    return 1;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    return  self.tableArray.count;
}

#define CELL_HEIGHT 115
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
    OrderModel *orderModel=[self.tableArray objectAtIndex:indexPath.row];
    CGFloat cellHeight;
    if (orderModel.customer.length >15) {
        cellHeight = CELL_HEIGHT + 15;
    }
    else {
        cellHeight = CELL_HEIGHT;
    }
    if(orderModel.open){
        MainHandleTableCell *cell= [[MainHandleTableCell alloc] init];
        CGFloat heigt= cellHeight+[cell createStepView:orderModel].height;
        return heigt;
    }
    else{
        return cellHeight;
    }
}

- (UITableViewCell *) tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    
    MainHandleTableCell *cell = (MainHandleTableCell*)[tableView dequeueReusableCellWithIdentifier:@"MainHandleTableCell"];
    
    if(cell == nil)
    {
        cell = [[MainHandleTableCell alloc] init];
        
    }
    cell.selectionStyle = UITableViewCellSelectionStyleNone;
    cell.delegateVC = self;
    cell.model=[self.tableArray objectAtIndex:indexPath.row];
    cell.Refesh=^(OrderModel* model){
        [self.tableArray setObject:model atIndexedSubscript:indexPath.row];
        [self.tableView reloadRowsAtIndexPaths:@[indexPath] withRowAnimation:UITableViewRowAnimationFade];
        [self.tableView scrollToRowAtIndexPath:indexPath atScrollPosition:UITableViewScrollPositionBottom animated:YES];

    };
    return cell;
}

-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    
    [tableView deselectRowAtIndexPath:indexPath animated:YES];
    OrderModel *model = [self.tableArray objectAtIndex:indexPath.row];
    NSLog(@"订单类型是%@",model.type);
    if (model.orderType) {
        if ([model.orderType integerValue] > 2) {
            OrderDetailsVC *vc = [[OrderDetailsVC alloc]init];
            vc.orderCode = model.orderCode;
            [self.navigationController pushViewController:vc animated:YES];
        }
        else {
            CSMyOrderConfirmingTVC *view = [[CSMyOrderConfirmingTVC alloc]init];
            view.orderCode = model.orderCode;
            [self.navigationController pushViewController:view animated:YES];
        }
 
    }else{
        [Toolobject showTextWithMessage:@"服务器返回的订单类型不存在"];
    }
}

- (void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath
{
    
    UIView *view = [UIView new];
    view.backgroundColor = [UIColor clearColor];
    [tableView setTableFooterView:view];
    
    
    if ([tableView respondsToSelector:@selector(setSeparatorInset:)]) {
        [tableView setSeparatorInset:UIEdgeInsetsZero];
    }
    if ([tableView respondsToSelector:@selector(setLayoutMargins:)]) {
        [tableView setLayoutMargins:UIEdgeInsetsZero];
    }
    if ([cell respondsToSelector:@selector(setSeparatorInset:)]) {
        [cell setSeparatorInset:UIEdgeInsetsZero];
    }
    if ([cell respondsToSelector:@selector(setLayoutMargins:)]) {
        [cell setLayoutMargins:UIEdgeInsetsZero];
    }
}

#pragma mark- 其他事件
/**
 *  左button的点击事件（进入个人中心）
 *
 *  @param sender
 */
-(void)leftItem:(RZCustomButtom *)sender{
 
    UserCenterVC *vc = [[UserCenterVC alloc] init];
    
    [self.navigationController pushViewController:vc animated:YES];
}

- (void)touchMessageButton:(UIButton *)sender {
  
     MessageListTVC *vc = [[MessageListTVC alloc] init];
    [self.navigationController pushViewController:vc animated:YES];
}

-(void)rightItem:(RZCustomButtom *)sender{
    MessageVC *vc = [[MessageVC alloc]init];
    [self.navigationController pushViewController:vc animated:YES];
}
 

#pragma mark- 网络请求
#pragma mark 添加下拉刷新
- (void)addHeader
{
    if(self.tableView.header==nil){
        __weak __typeof(self) weakSelf = self;
        // 添加上拉刷新头部控件
        self.tableView.header = [MJRefreshNormalHeader headerWithRefreshingBlock:^{
            if(isMJRefresh){
                isMJRefresh=NO;
                // 进入刷新状态后会自动调用这个block
                [weakSelf getHomepageDatas];
            }
        }];
        // 马上进入刷新状态
        [self.tableView.header beginRefreshing];
    }
    else
    {
        // 马上进入刷新状态
        [self.tableView.header beginRefreshing];
    }
}

- (void)getHomepageDatas {
    [self requestOrdersStatistical];
    [self requestData];
}


/**
 *获取消息数据
 */
- (void)getMessage{
    
    [[BDHUD sharedManager] showBDHUD:self.view title:[THMangerTool language:@"HUD.title"]];
    
    [AFHttpTool postJsonDatawithUrl:@"messagesOrderBy" parameters:nil success:^(id responseObject) {
        [[BDHUD sharedManager] dismissHUD];
        if ([[[responseObject objectForKey:@"head"] objectForKey:@"status"] intValue] == 1) {
            NSArray *array = [responseObject objectForKey:@"data"];
            int unreadCount = 0;
            for (NSDictionary *dic in array) {
                if ([[dic objectForKey:@"unRead"] integerValue] > 0) {
                    unreadCount ++;
                }
            }
            if (unreadCount >0) {
                self.labPoint.hidden = NO;
            }else{
                self.labPoint.hidden = YES;
            }  
        }else {
            
            [[BDHUD sharedManager] showWords:[[responseObject objectForKey:@"head"] objectForKey:@"info"]];
        }
        
    } fail:^(id responseObject, NSError *error) {
        
        [[BDHUD sharedManager] dismissHUD];
        
        if ([[error.userInfo objectForKey:@"NSLocalizedDescription"] isEqualToString:@"请求超时。"]) {
            [[BDHUD sharedManager] showWords:[UtilCheck language:@"order.time.out"]];
        }else {
            [[BDHUD sharedManager] showWords:[UtilCheck language:@"order.network.interruption"]];
        }
    }];
    
}


/**
 *  获取首页订单数据
 */
-(void)requestOrdersStatistical{
   
    [AFHttpTool postJsonDatawithUrl:@"main" parameters:nil
                            success:^(id responseObject) {
                                if(1==[[[responseObject objectForKey:@"head"] objectForKey:@"status"] intValue]){
                                    
                                    if([[responseObject objectForKey:@"data"] isKindOfClass:[NSArray class]]){
                                        NSArray *data=[responseObject objectForKey:@"data"];
                                        
                                        if(data.count>1){
                                        [self createTHeaderView:data];
                                        }
                                        else{
                                               [self createTHeaderView:nil]; 
                                        }
                                    }
                                    else{
                                            [self createTHeaderView:nil];
                                    }
                                }
                                else{
                                        [self createTHeaderView:nil];
                                }
                            } fail:^(id responseObject, NSError *error) {
                                
                                NSLog(@"获取首页订单数据失败");
                                [self createTHeaderView:nil];
                                
                            }];
    
}


/**
 *  获取更新信息
 */
-(void)requestUpdateInfo{
    
    if ([Toolobject isAppStoreTestAccount]) {
        return;
    }
    
    [AFHttpTool postJsonDatawithUrl:@"appUpdate" parameters:nil
                            success:^(id responseObject) {
                               
                                if(1==[[[responseObject objectForKey:@"head"] objectForKey:@"status"] intValue]){
                                    
                                    NSDictionary *dataDict = [[responseObject objectForKey:@"data"] mutableCopy];
                                    
                                    NSLog(@"dataDict: %@",dataDict);
                                    NSLog(@"服务器的版本号是%@",[dataDict objectForKey:@"updateVersionName"]);
                                    NSLog(@"当前程序的版本号是%@",[HDXMangerTool getVersion]);
                                    
                                    if ([[dataDict objectForKey:@"updateVersionName"] isEqualToString: [HDXMangerTool getVersion]]) {
                                        return;
                                    }
                                   
                                    if ([dataDict objectForKey:@"forced"]!= nil && [[dataDict objectForKey:@"forced"] integerValue] == 0) {//非强制更新
                                        UIAlertController *alertC = [UIAlertController alertControllerWithTitle:[UtilCheck language:@"version.update"] message:
                                                                     [NSString stringWithFormat:@"%@",[dataDict objectForKey:@"updateContent"]]  preferredStyle:(UIAlertControllerStyleAlert)];
                                        
                                        UIAlertAction *logoutAction = [UIAlertAction actionWithTitle:[UtilCheck language:@"button.cancel"] style:(UIAlertActionStyleCancel) handler:nil];
                                        
                                        UIAlertAction *updateAction = [UIAlertAction actionWithTitle:[UtilCheck language:@"button.done"] style:(UIAlertActionStyleDefault) handler:^(UIAlertAction * _Nonnull action) {
                                            
                                            NSString *updateURLStr = [dataDict objectForKey:@"updateUrl"];
                                            NSURL *updateURL = [NSURL URLWithString:updateURLStr];
                                            
                                            if ([[UIApplication sharedApplication] canOpenURL:updateURL]) {
                                                //前往应用商店
                                                [[UIApplication sharedApplication] openURL:updateURL];
                                                
                                            }
                                            else {
                                                //前往应用商店
                                                [[UIApplication sharedApplication] openURL:[NSURL URLWithString:KEY_APPSTORE_URL]];
                                                
                                            }
                                           
                                        }];
                                        [alertC addAction:logoutAction];
                                        [alertC addAction:updateAction];
                                        [self presentViewController:alertC animated:YES completion:nil];
                                    } else if ([dataDict objectForKey:@"forced"]!= nil && [[dataDict objectForKey:@"forced"] integerValue] == 1){//强制更新
                                        
                                        UIAlertController *alertC = [UIAlertController alertControllerWithTitle:[THMangerTool language:@"version.update"] message:[NSString stringWithFormat:@"%@",[dataDict objectForKey:@"updateContent"]] preferredStyle:(UIAlertControllerStyleAlert)];
                                        
                                        UIAlertAction *logoutAction = [UIAlertAction actionWithTitle:[UtilCheck language:@"button.cancel"] style:(UIAlertActionStyleCancel) handler:^(UIAlertAction * _Nonnull action) {
                                            [THMangerTool removeAccount];
                                            [APPDELEGATESelf setUpMainViewControllerOrLoginViewController:NO];
                                        }];
                                        
                                        UIAlertAction *updateAction = [UIAlertAction actionWithTitle:[UtilCheck language:@"button.done"] style:(UIAlertActionStyleDefault) handler:^(UIAlertAction * _Nonnull action) {
                                            //前往应用商店
                                            [[UIApplication sharedApplication] openURL:[NSURL URLWithString:KEY_APPSTORE_URL]];
                                        }];
                                        
                                        [alertC addAction:logoutAction];
                                        [alertC addAction:updateAction];
                                        [self presentViewController:alertC animated:YES completion:nil];
                                    }

                                    
                                }
                                else{
                                    
                                }
                            } fail:^(id responseObject, NSError *error) {
                                
                                NSLog(@"获取更新数据失败");
                                
                            }];
    
}


//创建或者修改头
-(void)createTHeaderView:(NSArray*)arr{
    
    if(!arr){
    
        arr=@[@{@"type":@"1",@"typeName":@"未完成订单",@"count":@"0"},@{@"type":@"2",@"typeName":@"待发货",@"count":@"0"},@{@"type":@"3",@"typeName":@"待收货",@"count":@"0"},@{@"type":@"4",@"typeName":@"待返件",@"count":@"0"}];
    }
    
    
    self.headerView = [[MainTableHeaderView alloc] initHeaderView:arr];
    __weak __typeof__(self) weadSelf=self;
    self.headerView.viewblock=^(UICustomButtonType type){
        [weadSelf pushViewByType:type];
    };
    self.tableView.tableHeaderView=self.headerView;
    
    if(!self.headerView){
 
       
    }
    else{
        [self.headerView setValueArray:arr];
    }
    
}


/**
 *  获取首页订单数据
 */
-(void)requestData{
    [[BDHUD sharedManager] dismissHUD];
 
    NSDictionary *post=[NSDictionary dictionaryWithObjectsAndKeys:@"3",@"size",@"0",@"type",@"1",@"page", nil];
    [AFHttpTool postJsonDatawithUrl:@"ordersStatistical" parameters:[post mutableCopy]
                            success:^(id responseObject) {
                                isMJRefresh=YES;
                                [self.tableView.header endRefreshing];
                                [[BDHUD sharedManager] dismissHUD];
                                if(1==[[[responseObject objectForKey:@"head"] objectForKey:@"status"] intValue]){
                                    if([[responseObject objectForKey:@"data"] isKindOfClass:[NSArray class]]){
                                        NSArray *data=[responseObject objectForKey:@"data"];
                                        self.tableArray=[UtilCheck arraytoModel:data targetModel:@"OrderModel"];
            
//                                        if(self.tableArray.count<1){
//                                            [[BDHUD sharedManager] showNOneDataViewHUD:self.tableView top:120 title:[THMangerTool language:@"HUD.noOrderData"] onClick:^{
//                                                  [self addHeader];
//                                            }];
//                                        }

                                        [self.tableView reloadData];
                                    }
                                    else{
                                        [self.tableArray removeAllObjects];
                                        if(self.tableArray.count<1){
                                            [[BDHUD sharedManager] showNOneDataViewHUD:self.tableView top:120 title:[THMangerTool language:@"HUD.noOrderData"] onClick:^{
                                              [self addHeader];
                                            }];
                                        }
                                        [[BDHUD sharedManager] showWords:[THMangerTool language:@"HUD.nothing"]];
                                    }
                                }
                                else{
                                    //返回数据出问题 弹出服务器返回信息
                                    if([[[responseObject objectForKey:@"head"] allKeys] containsObject:@"info"]&&![UtilCheck DataIsNuLL:[[responseObject objectForKey:@"head"] objectForKey:@"info"]]){
                                        [[BDHUD sharedManager] showWords:[[responseObject objectForKey:@"head"] objectForKey:@"info"]];
                                    }
                                    else{
                                     [[BDHUD sharedManager] showWords:[THMangerTool language:@"HUD.nothing"]];
                                    }
                                    [self.tableArray removeAllObjects];
                                    if(self.tableArray.count<1){
                                        [[BDHUD sharedManager] showNOneDataViewHUD:self.tableView top:120 title:[THMangerTool language:@"HUD.noOrderData"] onClick:^{
                                            [self addHeader];
                                        }];
                                    }
                                }
                            } fail:^(id responseObject, NSError *error) {
                                isMJRefresh=YES;
                                [self.tableView.header endRefreshing];
                                [[BDHUD sharedManager] dismissHUD];
                                if ([[error.userInfo objectForKey:@"NSLocalizedDescription"] isEqualToString:@"请求超时。"]) {
                                    [[BDHUD sharedManager] showWords:[UtilCheck language:@"order.time.out"]];
                                }else {
                                    [[BDHUD sharedManager] showWords:[UtilCheck language:@"order.network.interruption"]];
                                }
                            }];

}


#pragma mark 界面跳转
-(void)pushViewByType:(UICustomButtonType)type {
    THUserInfoModel *userModel0=[THMangerTool getAccountInfo];

    NSLog(@"usertype是%@   servicePermissions是%@",userModel0.userType,userModel0.servicePermissions);
   
    
    switch (type) {
        case NSButtonOrderCreate ://新建
        {

            THUserInfoModel *userModel = [THMangerTool getAccountInfo];
            
            NSLog(@"%@",userModel.userType);

            if ([userModel.userType integerValue] == 1) {//客户
                
                if (userModel.servicePermissions.count >= 2) { //备件管理和替换一起
                    CSNewOrderVC *vc = [[CSNewOrderVC alloc]init];
                    [self.navigationController pushViewController:vc animated:YES];
                }
                else if (userModel.servicePermissions.count <= 1 && [userModel.servicePermissions[0]  integerValue] == 1) {//备件管理
                    CSNewOrderManageVC *vc = [[CSNewOrderManageVC alloc]init];
                    [self.navigationController pushViewController:vc animated:YES];
                }
                else{
                    CSNewOrderReplaceVC *vc = [[CSNewOrderReplaceVC alloc]init];
                    [self.navigationController pushViewController:vc animated:YES];

                }
                
            }else if ([userModel.userType integerValue] == 2 ) {//客服
                if (userModel.servicePermissions.count <= 1 && [userModel.servicePermissions[0]  integerValue] == 1) {
                    CSNewOrderServiceVC *vc = [[CSNewOrderServiceVC alloc]init];
                    [self.navigationController pushViewController:vc animated:YES];
                    }
                else {//备件替换
                        
                    CSNewOrderLCVC *vc = [[CSNewOrderLCVC alloc]init];
                    [self.navigationController pushViewController:vc animated:YES];
                }
            }
            else { // 仓管+客服
                
                if (userModel.servicePermissions.count > 1 && [userModel.userType integerValue] == 0) {
                    
                    CSNewOrderVC *vc = [[CSNewOrderVC alloc]init];
                    [self.navigationController pushViewController:vc animated:YES];
                }
                
                if (userModel.servicePermissions.count <= 1 && [userModel.servicePermissions[0]  integerValue] == 1) {
                   
                    CSNewOrderServiceVC *vc = [[CSNewOrderServiceVC alloc]init];
                    [self.navigationController pushViewController:vc animated:YES];
                    
                }
                else if (userModel.servicePermissions.count <= 1 && [userModel.servicePermissions[0]  integerValue] == 2){ //备件替换
                    
                    CSNewOrderLCVC *vc = [[CSNewOrderLCVC alloc]init];
                    [self.navigationController pushViewController:vc animated:YES];
                }
            }
            
            }
            break;
        case NSButtonOrderUpdate ://修改--->去待确定列表*
        {
            CMyOrderVC *vc = [[CMyOrderVC alloc]init];
            vc.type = 7;
            [self.navigationController pushViewController:vc animated:YES];
//            CunquHomeVC *vc =[[CunquHomeVC alloc]init];
//            [self.navigationController pushViewController:vc animated:YES];
        }
            break;
        case NSButtonOrderQuery ://库存查询
        {
            AppDelegate * app = (AppDelegate *)[UIApplication sharedApplication].delegate;
            app.shouldChangeOrientation = YES;
            StockInquiryVC *vc = [[StockInquiryVC alloc]init];
            [self presentViewController:vc animated:YES completion:nil];
            
        }
            break;
        case NSButtonShipmentReport ://已发货报告
        {
            AppDelegate * app = (AppDelegate *)[UIApplication sharedApplication].delegate;
            app.shouldChangeOrientation = YES;
            ShipmentReportVC *vc = [[ShipmentReportVC alloc]init];
            [self presentViewController:vc animated:YES completion:nil];
            
        }
            break;
        case NSButtonOrderInventory ://物品盘点
        {
            WCheckgoodsVC *vc = [[WCheckgoodsVC alloc]init];
            [self.navigationController pushViewController:vc animated:YES];
            
        }
            break;
        case NSButtonCustomerSmartCabinet ://智能柜
        {
            NSMutableArray *listmuArr = [NSMutableArray new];
            if (self.cabinetlistArr.count>0) {
                for (NSDictionary *dic in self.cabinetlistArr) {
                    [listmuArr addObject:[dic objectForKey:@"code"]];
                }
            }
            [BDAlertView showAlertWithTitle:[UtilCheck language:@"cunhomeVC.cabinet"] isChoice:NO otherTitles:listmuArr completion:^(BOOL cancelled, NSInteger selectedIndex) {
                if (selectedIndex==-1) {
                    return ;
                }
                CunquHomeVC *vc = [[CunquHomeVC alloc]init];
                vc.cabinetCode = listmuArr[selectedIndex];
                [[NSUserDefaults standardUserDefaults]setObject:listmuArr[selectedIndex] forKey:@"cabinetCode"];
                [self.navigationController pushViewController:vc animated:YES];
                
            }];
//            [self getSmartCabinet];
            
        }
            break;
        case NSButtonCustomerNoComplete ://未完成
        {
            CMyOrderVC *vc = [[CMyOrderVC alloc]init];
            vc.type = 1;
            [self.navigationController pushViewController:vc animated:YES];
            
        }
            break;
        case NSButtonCustomerNoDelivery ://待发货
        {
            CMyOrderVC *vc = [[CMyOrderVC alloc]init];
            vc.type = 2;
            [self.navigationController pushViewController:vc animated:YES];
            
        }
            break;
        case NSButtonCustomerNoReceipt ://待收货
        {
            CMyOrderVC *vc = [[CMyOrderVC alloc]init];
            vc.type = 3;
            [self.navigationController pushViewController:vc animated:YES];
            
        }
            break;
            
        case NSButtonCustomerNoParts ://待返件
        {
            CMyOrderVC *vc = [[CMyOrderVC alloc]init];
            vc.type = 4;
            [self.navigationController pushViewController:vc animated:YES];
            
            
        }
            break;
            
        case NSButtonCustomerNoSure ://待确认
        {
            CMyOrderVC *vc = [[CMyOrderVC alloc]init];
            vc.type = 5;
            [self.navigationController pushViewController:vc animated:YES];
            
        }
            break;
        case NSButtonMore ://更多----》去我的订单页面
        {
            CMyOrderVC *vc = [[CMyOrderVC alloc]init];
            [self.navigationController pushViewController:vc animated:YES];

        }
            break;
        default:
            break;
    }
}

/**
 *  获取当前智能柜列表
 */
- (void)getSmartCabinet{
    [AFHttpTool postJsonDatawithUrl:@"getSmartCabinet" parameters:nil
                            success:^(id responseObject) {
                                if(1==[[[responseObject objectForKey:@"head"] objectForKey:@"status"] intValue]){
                                    self.cabinetlistArr = [NSMutableArray new];
                                    [self.cabinetlistArr addObjectsFromArray:[responseObject objectForKey:@"data"]];
                                    
                                }
                            } fail:^(id responseObject, NSError *error) {
                                NSLog(@"获取智能柜列表失败");
                                [self createTHeaderView:nil];
                                
                            }];
}


@end
